package edu.bu.grocery.backingbean.datamodel;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import edu.bu.grocerylist.model.GroceryListItem;

/**
 * This class represents the list within the ShoppingList view.  We can use this to interact with the 
 * check-boxing of the items in the list
 * @author donlanp
 *
 */
public class GroceryListItemDataModel extends ListDataModel<GroceryListItem> implements SelectableDataModel<GroceryListItem>{
	
	public GroceryListItemDataModel(List<GroceryListItem> items){
		super(items);
	}
	

	public GroceryListItem getRowData(String rowKey) {
		System.out.println("Row: " + rowKey);
		@SuppressWarnings("unchecked")
		List<GroceryListItem> items = (List<GroceryListItem>) getWrappedData();
		for(GroceryListItem item: items){
			if(getRowKey(item).equals(rowKey)){
				return item;
			}
		}
		
		
		return null;
	}

	public Object getRowKey(GroceryListItem item) {
		return item.getListId() + " -- " + item.getCategoryId() + " -- " + item.getItemId();
	}

}
